package com.xujie.chat.server;

import com.xujie.chat.message.NettyConstant;
import com.xujie.chat.server.handler.ServerInit;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.NettyRuntime;
import io.netty.util.concurrent.DefaultThreadFactory;

/**
 * @author Xujie
 * @since 2024/12/28 18:04
 **/


public class ServerApplication {
	public static void main(String[] args) throws InterruptedException {
		NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
		NioEventLoopGroup workerGroup = new NioEventLoopGroup(NettyRuntime.availableProcessors(), new DefaultThreadFactory("nt_worker"));
		ServerBootstrap serverBootstrap = new ServerBootstrap();
		
		serverBootstrap.group(bossGroup, workerGroup)
						.channel(NioServerSocketChannel.class)
						.option(ChannelOption.SO_BACKLOG, 1024)
						.childHandler(new ServerInit());

		serverBootstrap.bind(NettyConstant.SERVER_IP, NettyConstant.SERVER_PORT).sync();
	}
}
